//全局路径设置
var common = {};
if (!window.location.origin) {
    window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
common.ctx = window.location.origin;
common.sctx = common.ctx + "/app";
common.baseUrl = "http://localhost:8081";
common.jobImgPathRoot = "http://47.99.105.142/jd/img/";
common.companyLogoPathRoot = "http://47.99.105.142/company/logo/";
common.debug = "off";
common.ajaxError = function (XMLHttpRequest, textStatus, errorThrown) {
    if (common.debug === "on") {
        var error = "提交服务器失败:"
            + "XMLHttpRequest.status=" + XMLHttpRequest.status
            + "XMLHttpRequest.readyState=" + XMLHttpRequest.readyState
            + "textStatus=" + textStatus;
        alert(error);
    }
    $(".overlay").hide();
    $(".delay").hide();
};

function validatePhoneNumber(val) {
    var reg = /^(\d{3,4})-(\d{7,8})/; //验证电话号码
    var regph = /[1][3-9][0-9]{9,9}/; //验证手机号码
    var re = val.match(reg);
    var reph = val.match(regph);
    if ((re == null && reph == null) || val.length > 11) {
        return false;
    }
    return true;
}

function validatePwd(phone, pwd) {
    var ajaxResult = false;
    $.ajax({
        url: common.ctx + '/app/validateUser',
        type: 'POST',
        async: false,
        data: {"pwd": pwd, "phone": phone},
        dataType: 'json',
        success: function (jsonData) {
            ajaxResult = jsonData.success && jsonData.data;
            return false;
        },
        error: common.ajaxError
    });

    if (!ajaxResult) {
        return false;
    }
    return true;
};

function validateVcode(phone, vcode) {
    var ajaxResult = false;
    $.ajax({
        url: common.ctx + '/sign/validateVcode',
        type: 'GET',
        async: false,
        data: {"vcode": vcode, "phoneNumber": phone},
        dataType: 'json',
        success: function (jsonData) {
            ajaxResult = jsonData.success;
            return false;
        },
        error: common.ajaxError
    });

    if (!ajaxResult) {
        return false;
    }
    return true;
};

/** 登出*/
function logout(jumpUrl) {
    http.get({
        url: common.sctx + '/j_spring_security_logout',
        success: function (res) {
            window.location.href = jumpUrl;
        }
    });
}


function controlValueIsEmpty(control, info) {
    if ($(".div_" + control).is(":visible")) {
        if ($("#" + control).val() === "") {
            alert("请输入" + info + "!");
            $("#" + control).focus();
            return false;
        }
    }
    return true;
}


/** 获取用户session */
common.userSession = function userSession(callback) {
    http.get({
        url: common.sctx + '/personal/user/getCurrentUser.do',
        success: function (data) {
            if (callback) {
                callback(data);
            }
        }
    });
};

/** 获取url参数*/
common.locationParams = function () {
    var url = location.search;
    var param = {};
    if (url.indexOf("?") !== -1) {
        var paramStr = url.substr(1);
        var paramStrArray = paramStr.split("&");
        for (var i = 0; i < paramStrArray.length; i++) {
            param[paramStrArray[i].split("=")[0]] = (paramStrArray[i].split("=")[1]);
        }
    }
    return param;
};

common.goTo = function(url){
    window.location.href = common.ctx + url + "?v="+((new Date()).getTime());
};